package com.kai.controller;

import com.kai.dto.ExpressOrderDTO;
import com.kai.dto.ExpressOrderQueryDTO;
import com.kai.result.PageResult;
import com.kai.service.ExpressService;
import com.kai.vo.ExpressOrderVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.kai.result.Result;

@Slf4j
@RestController
@RequestMapping("/express")
@Tag(name = "快递代取相关接口")
public class ExpressController {

    @Autowired
    private ExpressService expressService;

    //下单
    @Operation(summary = "下单接口")
    @PostMapping("/submit")
    public Result<ExpressOrderVO> submitExpress(@RequestBody ExpressOrderDTO expressOrderDTO) {
        log.info("下单接口 参数>: {}", expressOrderDTO);
        ExpressOrderVO expressOrderVO = expressService.submitExpress(expressOrderDTO);
        return Result.success(expressOrderVO);
    }


    @Operation(summary = "分页查询历史订单")
    @GetMapping("/historyorders")
    public Result<PageResult> getHistoryOrders(ExpressOrderQueryDTO expressOrderQueryDTO) {
        log.info("分页查询历史订单 {} ", expressOrderQueryDTO);
        PageResult pageResult = expressService.getHistoryOrders(expressOrderQueryDTO);
        return Result.success(pageResult);
    }


    @Operation(summary = "取消订单")
    @PutMapping("/cancelorder")
    public Result<Void> cancelOrder(Long expressId) {
        log.info("取消订单 订单id{} ", expressId);
        expressService.cancelOrder(expressId);
        return Result.success();
    }





}
